package com.sunjee.order.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Dict;
import com.framework.common.api.CommonResult;
import com.sunjee.dubbo.dto.SysUserDTO;
import com.sunjee.dubbo.service.system.SysUserApiService;
import com.sunjee.order.domain.Test;
import com.sunjee.order.service.TestService;
import com.sunjee.order.service.feign.SystemFeignService;
import io.seata.spring.annotation.GlobalTransactional;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author lihanbo
 */
@Api(tags = "项目默认")
@Controller
@Slf4j
public class IndexController {

    @DubboReference(check = false)
    private SysUserApiService sysUserApiService;

    @Autowired
    private SystemFeignService systemFeignService;
    @Autowired
    private TestService testService;

    @ApiOperation("getUserInfoDubbo")
    @PostMapping("/getUserInfoDubbo")
    @ResponseBody
    public CommonResult<?> getUserInfoDubbo() {
        SysUserDTO userInfo = sysUserApiService.getUserInfo(1L);
        return CommonResult.success(userInfo);
    }

    @GlobalTransactional
    @ApiOperation("getUserInfoFeign")
    @PostMapping("/getUserInfoFeign")
    @ResponseBody
    public CommonResult<?> getUserInfoFeign(@RequestBody Dict dict) {
        Test test = new Test();
        test.setName("test 时间：" + DateUtil.date().toString());
        testService.save(test);
        CommonResult<SysUserDTO> res = systemFeignService.getUserInfo(dict);
        return res;
    }

}
